#include <set>
#include <ctime>
#include <utility>
#include <string>
#include <map>
#include <iostream>
#include "warehouse.h"
#include "product.h"

using namespace std;
namespace a4
{
	
  
  warehouse::warehouse(string n, map<string,pair<string,int>> *UPC_lookup)
  {
    name = n;
    inventory = new map<string,product*>();
    busiest_day = pair<tm, int>();
    UPC_lookup_map = UPC_lookup;
		
  }
  
	void warehouse::begin_new_day()
	{
		
		int activity_count_for_day = 0;
		for( map<string,product*>::iterator iter = inventory->begin(); iter != inventory->end();iter ++)
		{
			
			activity_count_for_day += iter->second->getActivityCount();
			iter->second->calculate_expirations_for_new_day();
			
		}
		
		if(activity_count_for_day >= busiest_day.second)
		{
			busiest_day.first = current_date;
			busiest_day.second = activity_count_for_day;
		}
		current_date.tm_mday = current_date.tm_mday+1;
		
	}
	
	void warehouse::endOfList()
	{
		
		int activity_count_for_day = 0;
		
		
		if(activity_count_for_day >= busiest_day.second)
		{
			busiest_day.first = current_date;
			busiest_day.second = activity_count_for_day;
		}
		current_date.tm_mday = current_date.tm_mday+1;
		
	
	}
	
	
	void warehouse::addProduct(string UPC, int expiration)
	{
		product *temp_product = new product(UPC,expiration);
		inventory->insert(pair<string, product*>(UPC,temp_product));
	}
  
  void warehouse::set_start_day(tm day)
  {
		start_date = day;
		current_date = day;
		mktime(&day);
  }
	
  void warehouse::receive_item(string upc, int quantity)
  {
		product *temp =  inventory->find(upc)->second;
		temp->addItem(quantity);
  }
	
  void warehouse::satisfy_request(string upc, int quantity)
  {
		product *temp =  inventory->find(upc)->second;
		temp->removeItem(quantity);
  }
	
	bool warehouse::isStocked(string UPC)
	{
		product *temp =  inventory->find(UPC)->second;
		int result = temp->getTotalNumberOfItems();
		if(result > 0) return true;
		return false;
	}
	
	pair<std::tm, int> warehouse::get_busiest_day()
	{
		return busiest_day;
	}
 
	
	
  std::pair<std::tm, int> warehouse::calc_busiest_day()
  {
  }
	
  void warehouse::remove_expired()
  {
		
  }
	
};
